﻿using System;
using System.Collections.Generic;
using UD.GRAL.Entity;
using UD.GRAL.Service;
using UD.Seguridad.Entity;
using UD.Seguridad.Service;

namespace UD.SYSEXTUD
{
    public class Global : System.Web.HttpApplication
    {
        GRALService oGRALService = new GRALService();
        SeguridadService oSeguridadService = new SeguridadService();

        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup

            Application.Add(UtilesHelper.appGRALMunicipios, GetListaMunicipios());

            Application.Add(UtilesHelper.appGRALDepartamentos, GetListaDepartamentos());

            Application.Add(UtilesHelper.appGRALTipoDocumentos, GetListaTiposDocumento());

            Application.Add(UtilesHelper.appGRALTiposCursos, GetListaTiposCurso());

            Application.Add(UtilesHelper.appGRALProyectosCurricularesUD, GetProyectosCurricularesUD());

            Application.Add(UtilesHelper.appGRALFacultadesUD, GetFacultadesUD());

            Application.Add(UtilesHelper.appSEGURIDADModulos, GetModulos());

            Application.Add(UtilesHelper.appSEGURIDADProgramas, GetProgramas());
        }

        void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown
            Application[UtilesHelper.appGRALDepartamentos] = null;
            Application[UtilesHelper.appGRALMunicipios] = null;
            Application[UtilesHelper.appGRALTipoDocumentos] = null;
            Application[UtilesHelper.appGRALTiposCursos] = null;
            Application[UtilesHelper.appGRALProyectosCurricularesUD] = null;
            Application[UtilesHelper.appGRALFacultadesUD] = null;
            Application[UtilesHelper.appSEGURIDADModulos] = null;
            Application[UtilesHelper.appSEGURIDADProgramas] = null;
        }

        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

        }

        void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started

        }

        void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.

        }


        private List<Municipio> GetListaMunicipios()
        {
            return oGRALService.ConsultarMunicipios(null, null, null);
        }


        private List<TipoDocumento> GetListaTiposDocumento()
        {
            return oGRALService.ConsultarTipoDocumentos(null, null, null);
        }


        private List<Departamento> GetListaDepartamentos()
        {
            return oGRALService.ConsultarDepartamentos(null, null, null);
        }

        private List<TipoCurso> GetListaTiposCurso()
        {
            return oGRALService.ConsultarTipoCursos(null, null, null);
        }

        private List<FacultadUD> GetFacultadesUD()
        {
            return oGRALService.ConsultarFacultadUDs(null, null, null);
        }

        private List<ProyectoCurricularUD> GetProyectosCurricularesUD()
        {
            return oGRALService.ConsultarProyectoCurricularUDs(null, null, null);
        }

        private List<Modulo> GetModulos()
        {
            return oSeguridadService.ConsultarModulos(null, null, null);
        }

        private List<Programa> GetProgramas()
        {
            return oSeguridadService.ConsultarProgramas(null, null, null, null, null, null);
        }

    }
}
